<?php
 
load_control('datatable');

class term_list extends datatable
{
	var $count;
	
	function term_list($id, $user_id, $link_id=0, $return_zero=true, $form_name='0', $return_to='')
	{
		global $GO_CONFIG, $GO_SECURITY, $GO_MODULES, $GO_LANGUAGE, $GO_THEME, $GO_LINKS;
		
		$this->datatable($id, false, $form_name);
		$this->set_attribute('style','width:100%;margin-bottom:20px;margin-top:0px;');
		$return_to = !empty($return_to) ? $return_to : $_SERVER['PHP_SELF'];
		
		require($GO_LANGUAGE->get_language_file('term'));

		require_once($GO_MODULES->modules['term']['class_path']."term.class.inc");
		$term = new term();

		if($this->term == 'delete')
		{
			foreach($this->selected as $delete_term_id)
			{
				$delete_term_id =str_replace('4:', '', $delete_term_id);
				$term->delete_message($delete_term_id);
			}
		}elseif($this->term=='unlink') // 删除短消息附带的 链接， 也就是附属文件
		{
			global $GO_LINKS;
			
			foreach($this->selected as $term_id)
			{
				$term_id =str_replace('4:', '', $term_id);
				if($term = $term->get_message($term_id))
				{
					$GO_LINKS->delete_link($link_id, $term['link_id']);
				}
			}
		}
		
		$links = $link_id > 0 ? $GO_LINKS->get_links($link_id, 4) : false;
		// 错误回馈
		if (isset($feedback))
		{
			$p = new html_element('p', $feedback);
			$p->set_attribute('class','Error');
			$this->add_html_element($p);
		}
		// 搜索
		$tab = new table('term_table');
		
		$row = new table_row();
		$cell = new table_cell();
		
		$cell->add_html_element(new html_element('a', '关键字'));
		$cell->add_html_element(new input('text','search_name'));
		$cell->add_html_element(new button('搜索',"javascript:document.location='".htmlspecialchars($return_to)."';"));	
		$cell->add_html_element(new html_element('p'));
		$row->add_cell($cell);
		$tab->add_row($row);
		
		$this->add_outerhtml_element($tab);
		// 任务编号单元格
		$this->add_column(new table_heading('任务编号', 'title'));
		// 任务名称单元格
		$this->add_column(new table_heading('任务名称', 'send_uid'));
		// 任务类别单元格
		$this->add_column(new table_heading('任务类别', 'term_type'));
		// 操作
		$this->add_column(new table_heading('操作'));
		$th = new table_heading('&nbsp;');
		//$this->add_column($th);
		// 获得短消息总数
/*	$this->count = $notes->get_notes($user_id, 
		$links, 
		$this->sort_index, 
		$this->sql_sort_order, 
		$this->start, 
		$this->offset);
		// 设置分页
		$this->set_pagination($this->count);*/ $this->count = 1;
		// 遍历当前用户短消息内容
		if($this->count > 0)
		{
			//while($notes->next_record())
			//{
				$row = new table_row('4:'.$id);
				// 双击表格某一行，显示该行的信息  【该行可删除】
			/*	$row->set_attribute('ondblclick', 
							"javascript:window.location.href='".					
							$GO_MODULES->modules['message']['url'].'message.php?message_id='.$message->f('id').
							'&return_to='.urlencode($return_to)."';");	
			*/	$id = '1';
				$term_name='立项';
				$term_type='数据填写';
				$operation='查看 修改';
				// 任务编号单元格
				$cell = new table_cell(htmlspecialchars($id));
				$cell->set_attribute('width','20%');
				$row->add_cell($cell);
				// 任务名称单元格
				$cell = new table_cell($term_name);
				$cell->set_attribute('width','40%');
				$row->add_cell($cell);
				// 任务类别单元格
				$cell = new table_cell($term_type);
				$cell->set_attribute('width','30%');
				$row->add_cell($cell);					
				// 操作单元格
				$cell = new table_cell();
				$cell->set_attribute('width','10%');
				$link = new html_element('a','删除');
				$link->set_attribute('href','view_term.php');
				$cell->add_html_element($link);
				$row->add_cell($cell);
				// 将以上单元格加入该行			
				$this->add_row($row);	
			//}		
		}else
		{
			if($return_zero)
			{
				$row = new table_row();
				$cell = new table_cell($no_no_term);
				$cell->set_attribute('colspan','99');
				$row->add_cell($cell);
				$this->add_row($row);
			}else
			{
				$this->innerHTML = '';
				return false;
			}
		}
	}
}
